import { createRouter, createWebHistory } from 'vue-router'
import  rootRoutes  from '@/router/rootRoutes'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: rootRoutes
})


router.beforeEach(async (to, from, next) => {
  //自行实现路由拦截
  next()
})

router.afterEach((to) => {
  //自行实现页面标题和favicon设置 或者按照本标准meta.title/icon
  document.title = to.meta.title
  setFavicon(to.meta.icon)
})

function setFavicon(iconPath) {
  const link = document.querySelector("link[rel*='icon']") || document.createElement('link')
  link.href = iconPath || '@/assets/logo.webp' // 默认图标路径
  document.getElementsByTagName('head')[0].appendChild(link)
}

export default router
